package com.xunchi.haichuan.user.dao;

import java.util.List;

import com.netai.safedoc.common.dao.BaseEntityDAOImpl;
import com.xunchi.haichuan.user.model.UserPermission;

/**
 * 作者：kongxb<br>
 * 模块名称：用户模块<br>
 * 功能描述：用户权限对应关系数据存取实现<br>
 * 维护记录
 */
public class UserPermissionDAOImpl extends BaseEntityDAOImpl<UserPermission> implements UserPermissionDAO {

	/**
	 * 默认构造方法
	 */
	public UserPermissionDAOImpl() {
		super();
	}

	/**
	 * 构造方法
	 * 
	 * @param user
	 */
	public UserPermissionDAOImpl(Class<UserPermission> userPermission) {
		super(userPermission);
	}

	/**
	 * @see com.xunchi.haichuan.user.dao.UserPermissionDAO#checkPermission(java.lang.String, java.lang.String)
	 */
	public boolean checkPermission(String usrId, String permissionId) throws Exception {
		String hql = "from UserPermission where usrId = ? and permissionId = ?";
		List<UserPermission> list = findByHql(hql, usrId, permissionId);
		return !list.isEmpty();
	}

	/**
	 * @see com.xunchi.haichuan.user.dao.UserPermissionDAO#getPermissions(java.lang.String)
	 */
	public List<String> getPermissions(String usrId) throws Exception {
		String hql = "select permissionId from UserPermission where usrId = ?";
		return findByHql(hql, usrId);
	}

	/**
	 * @see com.xunchi.haichuan.user.dao.UserPermissionDAO#delete(java.lang.String, java.lang.String)
	 */
	public void delete(String usrId, String permissionId) throws Exception {
		String hql = "delete from UserPermission where usrId = ? and permissionId = ?";
		deleteByQuery(hql, new Object[] { usrId, permissionId });
	}

}
